﻿using HardcoreGame.Content.Items.Placeable.Banners;
using Terraria;
using Terraria.GameContent.Bestiary;
using Terraria.ID;
using Terraria.ModLoader;

namespace HardcoreGame.Content.NPCs.Enemies.Biomesa.Desert
{
    public class DesertSludge : ModNPC
    {
        public override void SetStaticDefaults()
        {
            Main.npcFrameCount[Type] = 3;
        }
        public override void SetDefaults()
        {
            NPC.buffImmune[20] = true;
            NPC.buffImmune[70] = true;
            NPC.width = 34;
            NPC.height = 28;
            NPC.aiStyle = 1;
            NPC.damage = 50;
            NPC.defense = 18;
            NPC.lifeMax = 150;
            NPC.HitSound = SoundID.NPCHit1;
            NPC.DeathSound = SoundID.NPCDeath1;
            NPC.alpha = 55;
            NPC.value = 400f;
            NPC.scale = 1.1f;
            NPC.knockBackResist = 0.8f;
            AIType = 141;
            AnimationType = 141;
            Banner = NPC.type;
            BannerItem = ModContent.ItemType<DesertSludgeBanner>();
        }
        public override void HitEffect(NPC.HitInfo hit)
        {
            if (NPC.life > 0)
            {
                for (int num399 = 0; num399 < hit.Damage / (double)NPC.lifeMax * 100.0; num399++)
                {
                    Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Sand, hit.HitDirection, -1f, NPC.alpha, default);
                }
            }
            else
            {
                for (int num400 = 0; num400 < 50; num400++)
                {
                    Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Sand, 2 * hit.HitDirection, -2f, NPC.alpha, default);
                }
            }
        }
        public override void ModifyNPCLoot(NPCLoot npcLoot)
        {
            var DropRules = Main.ItemDropsDB.GetRulesForNPCID(NPCID.ToxicSludge, false);
            foreach (var DropRule in DropRules)
            {
                npcLoot.Add(DropRule);
            }
        }
        public override float SpawnChance(NPCSpawnInfo spawnInfo)
        {
            if (spawnInfo.Player.ZoneDesert && Main.hardMode)
            {
                return 0.1f;
            }
            return 0f;
        }
        public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry)
        {
            bestiaryEntry.Info.AddRange([
                BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.Desert,
                new FlavorTextBestiaryInfoElement("Mods.HardcoreGame.NPCs.DesertSludge.Bestiary")
            ]);
        }
    }
}
